import { useState, useEffect } from "react";
import { Text, StyleSheet } from "react-native";
import moment from "moment";




const Counter = () => {
  const [currentTime, setCurrentTime] = useState(moment().format('hh:mm:ss A'));
  useEffect(() => {
    // 创建定时器
    const timer = setInterval(() => {
      setCurrentTime(moment().format('hh:mm:ss A'));
    }, 1000);

    // 组件卸载时清除定时器
    return () => clearInterval(timer);
  }, []);
  return <Text style={styles.timeText}>{currentTime}</Text>;
};

export default Counter;

const styles = StyleSheet.create({
    timeText: {
      fontSize: 30,
      fontWeight: '300',
    },
  });
